using NUnit.Framework;
using Tycho.Parser.Peg;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class IndentationTermSpecification {
        [Test]
        public void GetIndentationShouldReturnBeginBlock () {
            AssertIndentation (" ", "  ", Indentation.BeginBlock);
            AssertIndentation (" \t", " \t ", Indentation.BeginBlock);
        }

        [Test]
        public void GetIndentationShouldReturnEndBlock () {
            AssertIndentation (" ", "", Indentation.EndBlock);
            AssertIndentation ("\t ", "\t", Indentation.EndBlock);
            AssertIndentation ("\t", "", Indentation.EndBlock);
            AssertIndentation ("  ", null, Indentation.EndBlock);
            AssertIndentation (" ", null, Indentation.EndBlock);
        }

        [Test]
        public void GetIndentationShouldReturnStatementDelimiter () {
            AssertIndentation (" ", " ", Indentation.StatementDelimiter);
            AssertIndentation ("\t", "\t", Indentation.StatementDelimiter);
        }

        [Test]
        public void GetIndentationShouldReturnError () {
            AssertIndentation ("\t", " ", Indentation.Error);
            AssertIndentation ("    ", " \t  ", Indentation.Error);
        }

        private static void AssertIndentation (string currentIndent, string newIndent, Indentation indentation) {
            var term = new IndentationTerm (newIndent, null);

            Assert.That (term.GetIndentation (currentIndent), Is.EqualTo (indentation));
        }
    }
}